package net.lainiao.morethread.Chapter4.demo2;

import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * Created by Administrator on 2017/3/3.
 */
public class Server {
    private ThreadPoolExecutor executor;

    public Server() {
        executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(5);
    }

    public void executeTask(Task task){
        System.out.println("Server: A new Task has arrived ");
        executor.execute(task);
        System.out.println("Server: Pool Size:"+executor.getPoolSize());
        System.out.println("Server: Task Count:"+executor.getTaskCount());
        System.out.println("Server: Active Count:"+executor.getActiveCount());
        System.out.println("Server: Completed Tasks:"+executor.getCompletedTaskCount());
    }

    public void endServer(){
        executor.shutdown();
    }


}
